﻿using DLL.NET50.DB.CRUD;
using DLL.NET.DB.MS.Drugs.CRUD.Repository;
using DLL.NET50.DB.MS.Entity;
using DLL.NET60.DB.MS.Entity.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace DLL.NET.DB.MS.Drugs.CRUD.Service
{
    public interface IBaseDrugsService : IBaseService<adi_dic_drug>
    {
        List<DTO_adi_dic_drug> GetDrugs();

        List<DTO_adi_dic_drug> GetDrugs(int Count);

        List<DTO_adi_dic_drug> GetDrugs(Expression<Func<adi_dic_drug, bool>> @where);

        /// <summary>
        /// 查询药品
        /// </summary>
        /// <param name="drugCode"></param>
        /// <param name="pycode"></param>
        /// <param name="drugname"></param>
        /// <returns></returns>
        List<DTO_adi_dic_drug> GetDrugs(string drugCode, string pycode, string drugname);

        List<DTO_adi_dic_drug> SearchDrugsByDrugCode(string drugCode);

        List<DTO_adi_dic_drug> SearchDrugsByPyCode(string pycode);

        List<DTO_adi_dic_drug> SearchDrugsByApprovatNumber(string ApprovalNumber);

        List<DTO_adi_dic_drug> SearchByUniqueCode(string uniqueCode);

        /// <summary>
        /// 查询药品
        /// </summary>
        /// <param name="drugName"></param>
        /// <returns></returns>
        List<DTO_adi_dic_drug> SearchDrugsByName(string drugName);

        bool AddDrug(DTO_adi_dic_drug entityDTO);

        bool AddRangeDrugs(List<DTO_adi_dic_drug> entitysDTO);

        bool DeleteDrug(DTO_adi_dic_drug entityDTO);

        bool UpdateDrug(DTO_adi_dic_drug entityDTO);

        bool UpdateRangeDrugs(List<DTO_adi_dic_drug> entitysDTO);

        bool AddOrModify(DTO_adi_dic_drug entityDTO);

        bool SaveDrugs(DTO_adi_dic_drug entityDTO);

        bool IsExist_ByDrugUniqueCode(DTO_adi_dic_drug entityDTO);

        bool MS_SaveDrug(DTO_adi_dic_drug entityDTO);

        bool MS_IsExist(DTO_adi_dic_drug entityDTO);

        bool IsExistByCode(string drugCode);
    }

    public class CBaseDrugsService : BaseService<adi_dic_drug>, IBaseDrugsService
    {
        protected IBaseDrugsRepository _drugsRepository;

        public CBaseDrugsService(IBaseDrugsRepository repository) : base(repository)
        {
            this._drugsRepository = repository;
        }

        public List<DTO_adi_dic_drug> GetDrugs()
        {
            return _drugsRepository.GetDrugs();
        }

        public List<DTO_adi_dic_drug> GetDrugs(int Count)
        {
            return _drugsRepository.GetDrugs(Count);
        }

        public List<DTO_adi_dic_drug> GetDrugs(Expression<Func<adi_dic_drug, bool>> @where)
        {
            return _drugsRepository.GetDrugs(where);
        }

        /// <summary>
        /// 查询药品
        /// </summary>
        /// <param name="drugCode"></param>
        /// <param name="pycode"></param>
        /// <param name="drugname"></param>
        /// <returns></returns>
        public List<DTO_adi_dic_drug> GetDrugs(string drugCode, string pycode, string drugname)
        {
            return _drugsRepository.GetDrugs(drugCode, pycode, drugname);
        }

        public List<DTO_adi_dic_drug> SearchDrugsByDrugCode(string drugCode)
        {
            return _drugsRepository.SearchDrugsByDrugCode(drugCode);
        }

        public List<DTO_adi_dic_drug> SearchDrugsByPyCode(string pycode)
        {
            return _drugsRepository.SearchDrugsByPyCode(pycode);
        }

        public List<DTO_adi_dic_drug> SearchDrugsByApprovatNumber(string ApprovalNumber)
        {
            return _drugsRepository.SearchDrugsByApprovatNumber(ApprovalNumber);
        }

        public List<DTO_adi_dic_drug> SearchByUniqueCode(string uniqueCode)
        {
            return _drugsRepository.SearchByUniqueCode(uniqueCode);
        }

        /// <summary>
        /// 查询药品
        /// </summary>
        /// <param name="drugName"></param>
        /// <returns></returns>
        public List<DTO_adi_dic_drug> SearchDrugsByName(string drugName)
        {
            return _drugsRepository.SearchDrugsByName(drugName);
        }

        public bool AddDrug(DTO_adi_dic_drug entityDTO)
        {
            return _drugsRepository.AddDrug(entityDTO);
        }

        public bool AddRangeDrugs(List<DTO_adi_dic_drug> entitysDTO)
        {
            return _drugsRepository.AddRangeDrugs(entitysDTO);
        }

        public bool DeleteDrug(DTO_adi_dic_drug entityDTO)
        {
            return _drugsRepository.DeleteDrug(entityDTO);
        }

        public int DeleteRange(List<DTO_adi_dic_drug> entitysDTO)
        {
            return _drugsRepository.RemoveRange(entitysDTO);
        }

        public bool UpdateDrug(DTO_adi_dic_drug entityDTO)
        {
            return _drugsRepository.UpdateDrug(entityDTO);
        }

        public bool UpdateRangeDrugs(List<DTO_adi_dic_drug> entitiesDTO)
        {
            return _drugsRepository.UpdateRangeDrugs(entitiesDTO);
        }

        public bool AddOrModify(DTO_adi_dic_drug entityDTO)
        {
            return _drugsRepository.AddOrModify(entityDTO);
        }

        public bool SaveDrugs(DTO_adi_dic_drug entityDTO)
        {
            return (_drugsRepository.SaveDrug(entityDTO));
        }

        public bool IsExist_ByDrugUniqueCode(DTO_adi_dic_drug entityDTO)
        {
            return _drugsRepository.IsExist_ByDrugUniqueCode(entityDTO);
        }

        public bool MS_SaveDrug(DTO_adi_dic_drug entityDTO)
        {
            return _drugsRepository.MS_SaveDrug(entityDTO);
        }

        public bool MS_IsExist(DTO_adi_dic_drug entityDTO)
        {
            return _drugsRepository.MS_IsExistByDrugCode(entityDTO);
        }

        public bool IsExistByCode(string drugCode)
        {
            return _drugsRepository.IsExistByCode(drugCode);
        }
    }
}